package com.itlong.cloud.app.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.itlong.cloud.POJO.DTO.app.AppElevatorAuthDTO;
import com.itlong.cloud.POJO.DTO.app.old.AppOldIosDeviceListDTO;
import com.itlong.cloud.POJO.DTO.app.old.AppOldUserInfoDto;
import com.itlong.cloud.POJO.PO.DeviceCloudIntercomInfoPO;
import com.itlong.cloud.POJO.PO.DeviceElevatorInfoPO;
import com.itlong.cloud.POJO.PO.DeviceEntranceInfoPO;
import com.itlong.cloud.POJO.PO.ProjectPO;
import com.itlong.cloud.POJO.VO.app.AppElevatorAuthVO;
import com.itlong.cloud.POJO.VO.app.AppElevatorInfoVO;
import com.itlong.cloud.POJO.VO.app.AppEntranceOrCloudIntercomAuthVO;
import com.itlong.cloud.POJO.VO.app.old.*;
import com.itlong.cloud.app.dao.IAppOldHomeDao;
import com.itlong.cloud.app.dao.IAppOldRegisterDao;
import com.itlong.cloud.app.service.IAppOldHomeService;
import com.itlong.cloud.app.service.IAppOldRegisterService;
import com.itlong.cloud.enumerate.PropertyEquipTypeEnum;
import com.itlong.cloud.enumerate.oldapp.Code;
import com.itlong.cloud.enumerate.oldapp.Message;
import com.itlong.cloud.utils.date.DateUtil;
import com.itlong.cloud.utils.words.StringHandlerUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * <desc>
 *     旧版APP的首页服务层实现类
 * </desc>
 *
 * @createDate 2017/11/21
 */
@Service
public class AppOldHomeServiceImpl implements IAppOldHomeService{

    private static final Logger LOG = LoggerFactory.getLogger(AppOldHomeServiceImpl.class);

    @Autowired
    private IAppOldHomeDao iAppOldHomeDao;

    @Autowired
    private IAppOldRegisterDao iAppOldRegisterDao;

    @Autowired
    private IAppOldRegisterService iAppOldRegisterService;

    /**
     * <desc>
     *     旧版APP_查询用户
     * </desc>
     * @param phoneNo
     * @return
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public AppOldUserInfoDto getAppOldUserDtoByPhone(String phoneNo){
        AppOldUserInfoDto appOldUserInfoDto = iAppOldRegisterDao.selectDtoByPhone(phoneNo);
        return  appOldUserInfoDto;
    }

    /**
     * <desc>
     *     获取APP的推送信息
     * </desc>
     * @param userId
     * @param pushAutoIndex
     * @param projectId
     * @return
     * @createDate 2017/11/27
     * @author cuiduanwu
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public AppOldPushVO getAppOldPushVO(String userId,String pushAutoIndex,String projectId){
        //推送消息
        AppOldPushVO appOldPushVO = new AppOldPushVO();
        Map<String,Object> pushparam = new HashMap<>();
        pushparam.put("userId",userId);
        if (StringUtils.isNotBlank(pushAutoIndex)){
            pushparam.put("pushInfoId",pushAutoIndex);
        }else {
            pushparam.put("projectId",projectId);
        }
        Map<String,Object> pushmap = iAppOldHomeDao.getPushInfo(pushparam);
        if (pushmap != null){
            if (pushmap.containsKey("autoIndex")&&StringUtils.isNotBlank(pushmap.get("autoIndex")+"")){
                appOldPushVO.setAutoIndex(pushmap.get("autoIndex").toString());
            }
            if (pushmap.containsKey("infoContent")&&StringUtils.isNotBlank(pushmap.get("infoContent")+"")){
                appOldPushVO.setInfoContent(pushmap.get("infoContent").toString());
            }
        }
        return  appOldPushVO;
    }

    /**
     * <desc>
     *     获取APP的广告信息
     * </desc>
     * @param userId
     * @param projectId
     * @return
     * @createDate 2017/11/27
     * @author cuiduanwu
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<AppOldAdVo> getAppOldAd(String userId,String projectId){
        List<AppOldAdVo> adsArr = new ArrayList<>();
        Map<String,Object> adparam = new HashMap<>();
        adparam.put("currentPage", 0);
        adparam.put("pageSize", 6);
        adparam.put("type", "1"); // 首页版块
        adparam.put("userId",userId);
        if (StringUtils.isNotEmpty(projectId)) {
            adparam.put("projectId",projectId);
        }

        List<Map<String,Object>> adList = iAppOldHomeDao.getAdInfo(adparam);
        if (adList != null&&adList.size()>0){
            for (Map admap:adList){
                if (admap.containsKey("adId")&&StringUtils.isNotBlank(admap.get("adId")+"")&&admap.containsKey("title")){
                    AppOldAdVo appOldAdVo = new AppOldAdVo(admap.get("adId").toString(),admap.get("title").toString(),"1","");
                    //查广告图片
                    Map<String,Object> imgmap = iAppOldHomeDao.getAdImg(admap.get("adId").toString());
                    if (imgmap != null){
                        if (imgmap.containsKey("imgUrl")){
                            appOldAdVo.setImgUrl(imgmap.get("imgUrl").toString());
                        }
                        if (imgmap.containsKey("jmgUrl")){
                            appOldAdVo.setJumpUrl(imgmap.get("jmgUrl").toString());
                        }
                    }
                    adsArr.add(appOldAdVo);
                }
            }
        }
        return adsArr;
    }

    /**
     * <desc>
     * 根据用户Id和用户Id获取用户项目资料列表.
     * </desc>
     *
     * @param  userId
     *  @param projectId 项目Id，若为空字符串，则查询该用户所有项目的资料列表
     * @return 项目资料列表
     * @author LewisLouis
     * @createDate 2017-12-05
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<Map<String, Object>> getUserProject(String userId, String projectId) {
        Map<String,Object> projectparam = new HashMap<>();
        projectparam.put("userId",userId);
        if (StringUtils.isNotBlank(projectId)){
            projectparam.put("projectId",projectId);
        }
        return iAppOldHomeDao.getUserProject(projectparam);
    }

    /**
     * <desc>
     * 查询用户在指定项目的有权限的门禁设备信息.
     * </desc>
     *
     * @param userId      用户Id（查询参数）
     * @param projectId   项目编号（查询参数）
     * @param currentPage 当前页（查询参数）
     * @param pageSize    单页数量 （查询参数）
     * @param cardNum     软卡号
     * @param pubKey      项目公钥
     * @return 有权限的门禁设备列表
     * @author LewisLouis
     * @createDate 2017-12-05
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<AppOldDeviceVO> getUserEntranceAuthList(String userId, String projectId, String currentPage,
                                                        String pageSize, String cardNum, String pubKey) throws Exception {
        List<AppOldDeviceVO> dl = new ArrayList<>();
        //第一步 查询用户拥有权限的门禁设备列表
        Map<String,Object> deviceauthmap = new HashMap<>();
        deviceauthmap.put("userId",userId);
        deviceauthmap.put("currentPage",currentPage);
        deviceauthmap.put("pageSize",pageSize);
        deviceauthmap.put("deviceStatus",1); //启用状态的设备
        deviceauthmap.put("projectId",projectId);
        List<Map<String,Object>> userDoorList = iAppOldHomeDao.getUserDoorList(deviceauthmap);
        AppEntranceOrCloudIntercomAuthVO appEntranceOrCloudIntercomAuthVOInDoor
                = StringHandlerUtil.converEntranceOrCloudIntercomAuth(PropertyEquipTypeEnum.ENTRANCE.getType(),userDoorList);
        if (appEntranceOrCloudIntercomAuthVOInDoor != null && !appEntranceOrCloudIntercomAuthVOInDoor.getDeviceIds().isEmpty()){
            List<String> entranceIdList = appEntranceOrCloudIntercomAuthVOInDoor.getDeviceIds();
            //第二步， 从门禁设备资料表中获取有权限的门禁设备名称等信息
            List<DeviceEntranceInfoPO> deviceEntranceInfoPOs = iAppOldHomeDao.getUserEntranceList(entranceIdList,projectId);
            if (deviceEntranceInfoPOs != null&&deviceEntranceInfoPOs.size()>0){
                for (DeviceEntranceInfoPO doorPO:deviceEntranceInfoPOs){
                    AppOldDeviceVO appOldDeviceDoorVO = new AppOldDeviceVO(doorPO.getDeviceName(), PropertyEquipTypeEnum.ENTRANCE.getType(),doorPO.getDeviceId(),
                            DateUtil.parseString("yyyy-MM-dd HH:mm:ss",appEntranceOrCloudIntercomAuthVOInDoor.getValiTime()).getTime(),"1",
                            doorPO.getDeviceUnique(),doorPO.getOpenThreshold(),cardNum,
                            pubKey,"8");
                    appOldDeviceDoorVO = (AppOldDeviceVO)StringHandlerUtil.formatString(appOldDeviceDoorVO);
                    dl.add(appOldDeviceDoorVO);
                }
            }
        }
        return dl;
    }

    /**
     * <desc>
     * 查询用户在指定项目的有权限的电梯设备信息.
     * </desc>
     *
     * @param userId      用户Id（查询参数）
     * @param projectId   项目编号（查询参数）
     * @param currentPage 当前页（查询参数）
     * @param pageSize    单页数量 （查询参数）
     * @param cardNum     软卡号
     * @param pubKey      项目公钥
     * @return 有权限的电梯设备列表
     * @author LewisLouis
     * @createDate 2017-12-05
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<AppOldDeviceVO> getUserElevatorAuthList(String userId, String projectId, String currentPage,
                                                        String pageSize, String cardNum, String pubKey) throws Exception {
        List<AppOldDeviceVO> dl = new ArrayList<>();
        List<AppOldDeviceVO> rmdl = new ArrayList<>();  //电梯的权限码全为0，非法业务数据，移除
        Map<String,Object> deviceauthmap = new HashMap<>();
        deviceauthmap.put("userId",userId);
        deviceauthmap.put("currentPage",currentPage);
        deviceauthmap.put("pageSize",pageSize);
        deviceauthmap.put("deviceStatus",1); //启用状态的设备
        deviceauthmap.put("projectId",projectId);
        List<AppElevatorAuthDTO> userFloorList = iAppOldHomeDao.getUserFloorList(deviceauthmap);
        AppElevatorAuthVO appElevatorAuthVO = StringHandlerUtil.convertElevatorAuth(userFloorList);
        if (appElevatorAuthVO != null&&StringUtils.isNotBlank(appElevatorAuthVO.getDeviceId())){
            List<AppElevatorInfoVO> elevatorAuthList = appElevatorAuthVO.getElevatorAuth();  //解码后的电梯权限对象集合
            String[] floorIdArr = StringHandlerUtil.splitString(appElevatorAuthVO.getDeviceId());
            List<String> floorIdList = Arrays.asList(floorIdArr);
            List<DeviceElevatorInfoPO> deviceFloorInfoPOs = iAppOldHomeDao.getUserElevatorFloorList(floorIdList,projectId); //启用状态，用户有权限的电梯集合
            if (deviceFloorInfoPOs != null&&deviceFloorInfoPOs.size()>0){
                for(DeviceElevatorInfoPO deviceFloorInfoPO:deviceFloorInfoPOs){
                    for (AppElevatorInfoVO appElevatorInfoVO:elevatorAuthList){
                        if (appElevatorInfoVO.getDeviceId().equals(deviceFloorInfoPO.getDeviceId())){
                            String floorAuth = StringHandlerUtil.getAuthCodeBynNturalFloors(StringHandlerUtil.filterLastComma(appElevatorInfoVO.getLiveFloor()));

                            String liveFloor = StringHandlerUtil.filterLastComma(appElevatorInfoVO.getLiveFloor());
                            String liveChoiceFloor = StringHandlerUtil.filterLastComma(appElevatorInfoVO.getLiveChoiceFloor());
                            String commonChoiceFloor = StringHandlerUtil.filterLastComma(appElevatorInfoVO.getCommonChoiceFloor());

                            AppOldDeviceVO appOldDeviceFloorVO = new AppOldDeviceVO(deviceFloorInfoPO.getDeviceName(),PropertyEquipTypeEnum.ELEVATOR.getType(),deviceFloorInfoPO.getDeviceId(),
                                    DateUtil.parseString("yyyy-MM-dd HH:mm:ss",appElevatorAuthVO.getVailTime()).getTime(),"1",
                                    deviceFloorInfoPO.getDeviceUnique(),deviceFloorInfoPO.getOpenThreshold(),cardNum,pubKey,floorAuth,
                                    deviceFloorInfoPO.getCommonFloor(),liveFloor,commonChoiceFloor,liveChoiceFloor);
                            if (StringUtils.isNotBlank(deviceFloorInfoPO.getCommonFloor())){
                                List<String> commonFloorList = Arrays.asList(deviceFloorInfoPO.getCommonFloor().split(","));
                                String commonLogicalFloor = iAppOldHomeDao.getLogicalFloor(commonFloorList, deviceFloorInfoPO.getDeviceUnique());
                                appOldDeviceFloorVO.setCommonLogicalFloor(commonLogicalFloor);
                            }
                            if (StringUtils.isNotBlank(appElevatorInfoVO.getLiveFloor())){
                                List<String> liveFloorList = Arrays.asList(StringHandlerUtil.filterLastComma(appElevatorInfoVO.getLiveFloor()).split(","));
                                String liveLogicalFloor = iAppOldHomeDao.getLogicalFloor(liveFloorList, deviceFloorInfoPO.getDeviceUnique());
                                appOldDeviceFloorVO.setLiveLogicalFloor(liveLogicalFloor);
                            }
                            appOldDeviceFloorVO = (AppOldDeviceVO)StringHandlerUtil.formatString(appOldDeviceFloorVO);
                            dl.add(appOldDeviceFloorVO);
                            if (StringUtils.isBlank(appOldDeviceFloorVO.getLiveFloor())){
                                rmdl.add(appOldDeviceFloorVO);
                            }
                        }
                    }
                }
            }
        }
        if (rmdl.size()>0){ //电梯的权限码全为0，非法业务数据，移除
            LOG.info("【旧版SDK-getUserElevatorAuthList-用户在指定项目的有权限的电梯设备信息，数据异常】"+JSONObject.toJSONString(rmdl));
            dl.removeAll(rmdl);
        }
        return dl;
    }

    /**
     * <desc>
     * 查询用户在指定项目的有权限的云对讲设备信息.
     * </desc>
     *
     * @param userId         用户Id（查询参数）
     * @param projectId      项目编号（查询参数）
     * @param currentPage    当前页（查询参数）
     * @param pageSize       单页数量 （查询参数）
     * @param cardNum        软卡号
     * @param pubKey         项目公钥
     * @param sipAddress     sip服务器地址
     * @param sipPort        sip服务器端口
     * @param userSipAccount sip账号
     * @param userSipPsd     sip密码
     * @return 有权限的云对讲设备列表
     * @author LewisLouis
     * @createDate 2017-12-05
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<AppOldDeviceVO> getUserIntercomAuthList(String userId, String projectId, String currentPage,
                                                        String pageSize, String cardNum, String pubKey, String sipAddress,
                                                        String sipPort, String userSipAccount, String userSipPsd) throws Exception {
        List<AppOldDeviceVO> dl = new ArrayList<>();
        Map<String,Object> deviceauthmap = new HashMap<>();
        deviceauthmap.put("userId",userId);
        deviceauthmap.put("currentPage",currentPage);
        deviceauthmap.put("pageSize",pageSize);
        deviceauthmap.put("deviceStatus",1); //启用状态的设备
        deviceauthmap.put("projectId",projectId);
        List<Map<String,Object>> userCloudDoorList = iAppOldHomeDao.getUserCloudDoorList(deviceauthmap);
        AppEntranceOrCloudIntercomAuthVO appEntranceOrCloudIntercomAuthVOInCloudDoor
                = StringHandlerUtil.converEntranceOrCloudIntercomAuth(PropertyEquipTypeEnum.CLOUD_INTERCOM.getType(),userCloudDoorList);
        if (appEntranceOrCloudIntercomAuthVOInCloudDoor != null){
            List<String> cloudDoorIdList = appEntranceOrCloudIntercomAuthVOInCloudDoor.getDeviceIds();
            List<DeviceCloudIntercomInfoPO> deviceCloudIntercomInfoPOs = iAppOldHomeDao.getUserCloudIntercomDoorList(cloudDoorIdList,projectId);
            if (deviceCloudIntercomInfoPOs != null&&deviceCloudIntercomInfoPOs.size()>0){
                for (DeviceCloudIntercomInfoPO cloudDoorPO:deviceCloudIntercomInfoPOs){
                    AppOldDeviceVO appOldDeviceCloudDoorVO = new AppOldDeviceVO(cloudDoorPO.getDeviceName(),
                            PropertyEquipTypeEnum.CLOUD_INTERCOM.getType(),cloudDoorPO.getDeviceId(),
                            new Date().getTime(),"1",cloudDoorPO.getDeviceUnique(),"",cardNum,pubKey,"8");
                    if (StringUtils.isNotBlank(cloudDoorPO.getSipAccount())){
                        appOldDeviceCloudDoorVO.setSipAccount(cloudDoorPO.getSipAccount()+"@"+sipAddress+":"+sipPort);
                        appOldDeviceCloudDoorVO.setSipPsd(cloudDoorPO.getSipPsd());
                    }
                    Map<String,Object> roomparam = new HashMap<>();
                    roomparam.put("userId", userId); ///appOldUserInfoDto.getUserId());
                    roomparam.put("deviceUnique", cloudDoorPO.getDeviceUnique());
                    roomparam.put("smartType",cloudDoorPO.getSmartType());
                    roomparam.put("projectId",cloudDoorPO.getProjectId());
                    List<AppOldDeviceServeRoomVO> roomVOs = iAppOldHomeDao.getUserRoomInCloudDoorList(roomparam);
                    if (roomVOs != null&&roomVOs.size()>0){
                        for (AppOldDeviceServeRoomVO appOldDeviceServeRoomVO:roomVOs){
                            if (StringUtils.isNotBlank(userSipAccount)){
                                appOldDeviceServeRoomVO.setSipAccount(userSipAccount+"@"
                                        +sipAddress+":"+sipPort);
                            }
                            if (StringUtils.isNotEmpty(userSipPsd)){
                                appOldDeviceServeRoomVO.setSipPsd(userSipPsd);
                            }
                            appOldDeviceServeRoomVO.setProjectId(cloudDoorPO.getProjectId());
                        }
                        appOldDeviceCloudDoorVO.setRoomArr(roomVOs);
                    }
                    dl.add(appOldDeviceCloudDoorVO);
                }
            }
        }
        return dl;
    }

    /**
     * <desc>
     *      获取IOS设备列表
     * </desc>
     *
     * @param dto
     * @return
     * @author jiaqi.X
     * @createDate 2018/01/12
     */
    public List<AppOldDeviceVO> getIosDeviceList(AppOldIosDeviceListDTO dto) throws Exception {
        List<AppOldDeviceVO> dl = new ArrayList<>();
        Map<String,Object> deviceauthmap=new HashMap<>();
        deviceauthmap.put("projectId", dto.getProjectId());
        deviceauthmap.put("userId",dto.getUserId());
        //查询用户门禁设备列表
        List<Map<String,Object>> userDoorList = iAppOldHomeDao.getUserDoorList(deviceauthmap);
        AppEntranceOrCloudIntercomAuthVO appEntranceOrCloudIntercomAuthVOInDoor = StringHandlerUtil.converEntranceOrCloudIntercomAuth(PropertyEquipTypeEnum.ENTRANCE.getType(),userDoorList);
        if (appEntranceOrCloudIntercomAuthVOInDoor != null && !appEntranceOrCloudIntercomAuthVOInDoor.getDeviceIds().isEmpty()){
            List<String> entranceIdList = appEntranceOrCloudIntercomAuthVOInDoor.getDeviceIds();
            List<DeviceEntranceInfoPO> deviceEntranceInfoPOs = iAppOldHomeDao.getUserEntranceList(entranceIdList,dto.getProjectId());
            if (deviceEntranceInfoPOs != null&&deviceEntranceInfoPOs.size()>0){
                for (DeviceEntranceInfoPO doorPO:deviceEntranceInfoPOs){
                    AppOldDeviceVO appOldDeviceDoorVO = new AppOldDeviceVO(doorPO.getDeviceName(), PropertyEquipTypeEnum.ENTRANCE.getType(),doorPO.getDeviceId(),
                            DateUtil.parseString("yyyy-MM-dd HH:mm:ss",appEntranceOrCloudIntercomAuthVOInDoor.getValiTime()).getTime(),"1",doorPO.getDeviceUnique(),doorPO.getOpenThreshold(),dto.getCardNum(),dto.getPubKey(),"8");
                    appOldDeviceDoorVO.setProjectId(dto.getProjectId());
                    if (StringUtils.isNotBlank(appOldDeviceDoorVO.getDoorAuth())){
                        appOldDeviceDoorVO.setDoorAuth(appOldDeviceDoorVO.getDoorAuth().toUpperCase());
                    }
                    dl.add(appOldDeviceDoorVO);
                }
            }
        }
        //查询云对讲设备列表
        List<Map<String,Object>> userCloudDoorList = iAppOldHomeDao.getUserCloudDoorList(deviceauthmap);
        AppEntranceOrCloudIntercomAuthVO appEntranceOrCloudIntercomAuthVOInCloudDoor = StringHandlerUtil.converEntranceOrCloudIntercomAuth(PropertyEquipTypeEnum.CLOUD_INTERCOM.getType(),userCloudDoorList);
        if (appEntranceOrCloudIntercomAuthVOInCloudDoor != null){
            List<String> cloudDoorIdList = appEntranceOrCloudIntercomAuthVOInCloudDoor.getDeviceIds();
            List<DeviceCloudIntercomInfoPO> deviceCloudIntercomInfoPOs = iAppOldHomeDao.getUserCloudIntercomDoorList(cloudDoorIdList,dto.getProjectId());
            if (deviceCloudIntercomInfoPOs != null&&deviceCloudIntercomInfoPOs.size()>0){
                for (DeviceCloudIntercomInfoPO cloudDoorPO:deviceCloudIntercomInfoPOs){
                    AppOldDeviceVO appOldDeviceCloudDoorVO = new AppOldDeviceVO(cloudDoorPO.getDeviceName(),PropertyEquipTypeEnum.CLOUD_INTERCOM.getType(),cloudDoorPO.getDeviceId(),
                            new Date().getTime(),"1",cloudDoorPO.getDeviceUnique(),"",dto.getCardNum(),dto.getPubKey(),"8");
                    appOldDeviceCloudDoorVO.setProjectId(dto.getProjectId());
                    if (StringUtils.isNotBlank(cloudDoorPO.getSipAccount())){
                        appOldDeviceCloudDoorVO.setSipAccount(cloudDoorPO.getSipAccount()+"@"+dto.getSipAddress()+":"+dto.getSipPort());
                        appOldDeviceCloudDoorVO.setSipPsd(cloudDoorPO.getSipPsd());
                    }
                    Map<String,Object> roomparam = new HashMap<>();
                    roomparam.put("userId",dto.getUserId());
                    roomparam.put("deviceUnique", cloudDoorPO.getDeviceUnique());
                    roomparam.put("smartType",cloudDoorPO.getSmartType());
                    roomparam.put("projectId",StringHandlerUtil.getEmptyOrStr(cloudDoorPO.getProjectId()));
                    List<AppOldDeviceServeRoomVO> roomVOs = iAppOldHomeDao.getUserRoomInCloudDoorList(roomparam);
                    if (roomVOs != null&&roomVOs.size()>0){
                        for (AppOldDeviceServeRoomVO appOldDeviceServeRoomVO:roomVOs){
                            if (StringUtils.isNotBlank(dto.getUserSipAccount())){
                                appOldDeviceServeRoomVO.setSipAccount(dto.getUserSipAccount()+"@"+dto.getSipAddress()+":"+dto.getSipPort());
                            }
                            if (StringUtils.isNotEmpty(dto.getUserSipPsd())){
                                appOldDeviceServeRoomVO.setSipPsd(dto.getUserSipPsd());
                            }
                            appOldDeviceServeRoomVO.setProjectId(StringHandlerUtil.getEmptyOrStr(cloudDoorPO.getProjectId()));
                        }
                        appOldDeviceCloudDoorVO.setRoomArr(roomVOs);
                    }
                    dl.add(appOldDeviceCloudDoorVO);
                }
            }
        }
        //查询电梯设备列表
        List<AppElevatorAuthDTO> userFloorList = iAppOldHomeDao.getUserFloorList(deviceauthmap);
        AppElevatorAuthVO appElevatorAuthVO = StringHandlerUtil.convertElevatorAuth(userFloorList);
        if (appElevatorAuthVO != null&&StringUtils.isNotBlank(appElevatorAuthVO.getDeviceId())){
            List<AppElevatorInfoVO> elevatorAuthList = appElevatorAuthVO.getElevatorAuth();  //解码后的电梯权限对象集合
            String[] floorIdArr = StringHandlerUtil.splitString(appElevatorAuthVO.getDeviceId());
            List<String> floorIdList = Arrays.asList(floorIdArr);
            List<DeviceElevatorInfoPO> deviceFloorInfoPOs = iAppOldHomeDao.getUserElevatorFloorList(floorIdList,dto.getProjectId()); //启用状态，用户有权限的电梯集合
            if (deviceFloorInfoPOs != null&&deviceFloorInfoPOs.size()>0){
                for(DeviceElevatorInfoPO deviceFloorInfoPO:deviceFloorInfoPOs){
                    for (AppElevatorInfoVO appElevatorInfoVO:elevatorAuthList){
                        if (appElevatorInfoVO.getDeviceId().equals(deviceFloorInfoPO.getDeviceId())){
                            String floorAuth = StringHandlerUtil.getAuthCodeBynNturalFloors(StringHandlerUtil.filterLastComma(appElevatorInfoVO.getLiveFloor()));
                            AppOldDeviceVO appOldDeviceFloorVO = new AppOldDeviceVO(deviceFloorInfoPO.getDeviceName(),PropertyEquipTypeEnum.ELEVATOR.getType(),deviceFloorInfoPO.getDeviceId(),
                                    DateUtil.parseString("yyyy-MM-dd HH:mm:ss",appElevatorAuthVO.getVailTime()).getTime(),"1",deviceFloorInfoPO.getDeviceUnique(),deviceFloorInfoPO.getOpenThreshold(),dto.getCardNum(),dto.getPubKey(),floorAuth,
                                    deviceFloorInfoPO.getCommonFloor(),StringHandlerUtil.filterLastComma(appElevatorInfoVO.getLiveFloor()),StringHandlerUtil.filterLastComma(appElevatorInfoVO.getCommonChoiceFloor()),StringHandlerUtil.filterLastComma(appElevatorInfoVO.getLiveChoiceFloor()));
                            if (StringUtils.isNotBlank(deviceFloorInfoPO.getCommonFloor())){
                                List<String> commonFloorList = Arrays.asList(deviceFloorInfoPO.getCommonFloor().split(","));
                                String commonLogicalFloor = iAppOldHomeDao.getLogicalFloor(commonFloorList, deviceFloorInfoPO.getDeviceUnique());
                                appOldDeviceFloorVO.setCommonLogicalFloor(commonLogicalFloor);
                            }
                            List<String> liveFloorList = Arrays.asList(StringHandlerUtil.splitString(appElevatorInfoVO.getLiveFloor()));
                            String liveLogicalFloor="";
                            if(liveFloorList!=null && !liveFloorList.isEmpty()){
                                liveLogicalFloor = iAppOldHomeDao.getLogicalFloor(liveFloorList, deviceFloorInfoPO.getDeviceUnique());
                            }
                            appOldDeviceFloorVO.setLiveLogicalFloor(liveLogicalFloor);
                            appOldDeviceFloorVO.setProjectId(dto.getProjectId());
                            if (StringUtils.isNotBlank(appOldDeviceFloorVO.getFloorAuth())){
                                appOldDeviceFloorVO.setFloorAuth(appOldDeviceFloorVO.getFloorAuth().toUpperCase());
                            }
                            dl.add(appOldDeviceFloorVO);
                        }
                    }
                }
            }
        }
        return dl;
    }


    /**
     * <desc>
     *     旧版APP_open开门首页
     * </desc>
     * @param pushAutoIndex
     * @param phoneNo
     * @param pageSize
     * @param pageNo
     * @param projectId
     * @return
     * @throws Exception
     * @createDate 2017/11/21
     * @author cuiduanwu
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Message appOpen(String pushAutoIndex,String phoneNo,Integer pageSize,Integer pageNo,String projectId) throws Exception{
        JSONObject data = new JSONObject();
        AppOldUserInfoDto appOldUserInfoDto = iAppOldRegisterDao.selectDtoByPhone(phoneNo);
        if (appOldUserInfoDto == null){
            return  new Message(Code.TOKEN_ERR);
        }
        //查询用户权限
        JSONArray userProjectArr = new JSONArray();
        Map<String,Object> deviceauthmap = new HashMap<>();
        deviceauthmap.put("userId",appOldUserInfoDto.getUserId());
        deviceauthmap.put("currentPage",pageNo);
        deviceauthmap.put("pageSize",pageSize);
        deviceauthmap.put("deviceStatus",1); //启用状态的设备
        //查询用户拥有的项目列表
        Map<String,Object> projectparam = new HashMap<>();
        projectparam.put("userId",appOldUserInfoDto.getUserId());
        if (StringUtils.isNotBlank(projectId)){
            projectparam.put("projectId",projectId);
        }
        List<Map<String,Object>> userProjectList = iAppOldHomeDao.getUserProject(projectparam);
        if (userProjectList != null&&userProjectList.size()>0){
            String cardNum = "000000",pubKey = "";
            String userSipAccount = "",userSipPsd = "",sipAddress="",sipPort = ""; //用户在每个项目上的SIP账号与密码
            for (Map userprojectmap:userProjectList){
                JSONObject uprjs = new JSONObject();
                uprjs.put("projectId",userprojectmap.get("projectId").toString());
                uprjs.put("projectName",userprojectmap.get("projectName").toString());
                uprjs.put("userTypeInProject",userprojectmap.get("userType").toString());
                pubKey = userprojectmap.get("pubKey").toString();
                uprjs.put("pubKey",pubKey);
                if (userprojectmap.containsKey("cardNum")&&userprojectmap.get("cardNum") != null&&StringUtils.isNotBlank(userprojectmap.get("cardNum").toString())){
                    cardNum = userprojectmap.get("cardNum").toString();
                }
                uprjs.put("cardNum",cardNum);
                if (userprojectmap.containsKey("userSipAccount")&&userprojectmap.get("userSipAccount") != null&&StringUtils.isNotBlank(userprojectmap.get("userSipAccount").toString())){
                    userSipAccount = userprojectmap.get("userSipAccount").toString();
                }
                uprjs.put("userSipAccount",userSipAccount);
                if (userprojectmap.containsKey("userSipPsd")&&userprojectmap.get("userSipPsd") != null&&StringUtils.isNotBlank(userprojectmap.get("userSipPsd").toString())){
                    userSipPsd = userprojectmap.get("userSipPsd").toString();
                }
                uprjs.put("userSipPsd",userSipPsd);
                if (userprojectmap.containsKey("sipAddress")&&userprojectmap.get("sipAddress") != null&&StringUtils.isNotBlank(userprojectmap.get("sipAddress").toString())){
                    sipAddress = userprojectmap.get("sipAddress").toString();
                }
                uprjs.put("sipAddress",sipAddress);
                if (userprojectmap.containsKey("sipPort")&&userprojectmap.get("sipPort") != null&&StringUtils.isNotBlank(userprojectmap.get("sipPort").toString())){
                    sipPort = userprojectmap.get("sipPort").toString();
                }
                uprjs.put("sipPort",sipPort);
                userProjectArr.add(uprjs);
            }
        }
        data.put("deviceInfos", userProjectArr);
        return new Message(Code.SUCCESS, data);
    }


    /**
     *  <desc>
     *      旧版APP_获取用户信息
     *  </desc>
     * @param phoneNo
     * @param projectId
     * @param pswd
     * @param loginDevice
     * @param token
     * @return
     * @throws Exception
     * @createDate 2017/11/27
     * @author cuiduanwu
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Message getUserInfo(String phoneNo,String projectId,String pswd,String loginDevice,String token) throws Exception{
        AppOldUserInfoVO appOldUserInfoVO = new AppOldUserInfoVO();
        AppOldUserInfoDto appOldUserInfoDto = iAppOldRegisterDao.selectDtoByPhone(phoneNo);
        if (appOldUserInfoDto == null){
            return new Message(Code.NOT_FOUNDUSER);
        }
        if (appOldUserInfoDto.getUserStatus() != 1){
            return new Message(Code.USER_STATUSERR);
        }
        if (StringUtils.isNotBlank(projectId)){
            ProjectPO projectPO = iAppOldHomeDao.getProjectById(projectId);
            if (projectPO != null && 1 != projectPO.getStatus()){
                //LOG.info("【旧版APP_getUserInfo】"+projectId+"--项目未被启用");
                return new Message(Code.PROJECT_REFUSE);
            }
        }
        BeanUtils.copyProperties(appOldUserInfoDto,appOldUserInfoVO);
        if ("1".equals(appOldUserInfoDto.getSex())){
            appOldUserInfoVO.setSex("先生");
        }else {
            appOldUserInfoVO.setSex("女士");
        }
        appOldUserInfoVO.setPhoneNo(appOldUserInfoDto.getUserPhone());
        appOldUserInfoVO.setParentPhonetNo("");
        JSONObject js = iAppOldRegisterService.getUserProjectInfo(appOldUserInfoDto.getUserId(),projectId);
        appOldUserInfoVO.setUserId(appOldUserInfoDto.getUserId());
        appOldUserInfoVO.setProjectIds(js.getString("projectIds"));
        appOldUserInfoVO.setProjectNames(js.getString("projectNames"));
        appOldUserInfoVO.setUserTypeInProject(js.getString("userTypeInProject"));
        String userAuth = "N";
        if (StringUtils.isNotBlank(js.getString("userAuth"))){
            userAuth = js.getString("userAuth");
        }
        if ("Y".equals(userAuth)){
            //旧APP有邀请过家人（带房间信息）则为Y,否则为N
            Integer countChild = iAppOldHomeDao.countUserChild(appOldUserInfoDto.getUserId(),projectId);
            if (countChild==0){
                userAuth = "N";
            }
        }
        appOldUserInfoVO.setUserAuth(userAuth);
        appOldUserInfoVO.setOwnerAddress(js.getString("ownerAddress"));
        appOldUserInfoVO.setAuthMaxNum(js.getString("authMaxNum"));
        appOldUserInfoVO.setAuthNum(js.getString("authNum"));

        appOldUserInfoVO.setAroundProjectIds(js.getString("aroundProjectIds"));
        appOldUserInfoVO.setAroundProjectNames(js.getString("aroundProjectNames"));
        appOldUserInfoVO.setCurrentProjectId(js.getString("currentProjectId"));
        appOldUserInfoVO.setCurrentProjectName(js.getString("currentProjectName"));
        appOldUserInfoVO.setPubKeys(js.getString("pubKeys"));
        appOldUserInfoVO.setServerUrls(js.getString("serverUrls"));
        appOldUserInfoVO.setIsAllowPhone(js.getString("isAllowPhone"));

        appOldUserInfoVO.setDoorPwd(js.getString("doorPwd"));
        appOldUserInfoVO.setCenterPhoneNo(js.getString("centerPhoneNo"));
        appOldUserInfoVO.setTurnServer(js.getString("turnServer"));
        iAppOldRegisterService.saveCacheUserVO(appOldUserInfoVO);
        appOldUserInfoVO=(AppOldUserInfoVO)StringHandlerUtil.formatString(appOldUserInfoVO);
        if (StringUtils.isNotBlank(appOldUserInfoVO.getPhotoUrl())){
            String picurl = appOldUserInfoVO.getPhotoUrl();
            String picurlchild = picurl.substring(picurl.indexOf("//")+2,picurl.length());
            appOldUserInfoVO.setPhotoUrl(picurlchild.substring(picurlchild.indexOf("/"),picurlchild.length()));
        }
        return new Message(Code.SUCCESS,appOldUserInfoVO);
    }



    /**
     * <desc>
     *     旧版APP_home开门首页
     * </desc>
     * @param pushAutoIndex
     * @param phoneNo
     * @param pageSize
     * @param pageNo
     * @param projectId
     * @return
     * @throws Exception
     * @createDate 2017/11/27
     * @author cuiduanwu
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Message appHome(String pushAutoIndex,String phoneNo,Integer pageSize,Integer pageNo,String projectId) throws Exception{
        JSONObject data = new JSONObject();
        AppOldUserInfoDto appOldUserInfoDto = iAppOldRegisterDao.selectDtoByPhone(phoneNo);
        if (appOldUserInfoDto == null){
            return  new Message(Code.TOKEN_ERR);
        }
        if(StringUtils.isNotBlank(projectId)){
            JSONArray jsonArray=this.getHomeDeviceByProjectId(appOldUserInfoDto.getUserId(),projectId);
            data.put("deviceInfos",jsonArray);
        }else{
            List<AppOldDeviceVO> dls=new ArrayList<>();
            //查询用户拥有的项目列表
            List<String> userProjectList = iAppOldHomeDao.getUserProjectIds(appOldUserInfoDto.getUserId());
            for(String project:userProjectList){
                JSONArray jsonArray=this.getHomeDeviceByProjectId(appOldUserInfoDto.getUserId(),project);
                for(int i=0;i<jsonArray.size();i++){
                    List<AppOldDeviceVO> dl=(List<AppOldDeviceVO>)jsonArray.getJSONObject(i).get("deviceinfoArr");
                    dl.forEach(vo-> {
                        dls.add(vo);
                    });
                }
            }
            data.put("deviceInfos",dls);
        }
        return  new Message(Code.SUCCESS,data);
    }

    /**
     * <desc>
     *      获取用户拥有的项目列表
     * </desc>
     *
     * @param userId
     * @return
     * @author Jiaqi.X
     * @createDate 2018/01/12
     */
    public List<String> getUserProjectList(String userId){
        return iAppOldHomeDao.getUserProjectIds(userId);
    }

    /**
     * <desc>
     *      获取旧APP安卓用户设备列表
     * </desc>
     *
     * @param userId 用户id
     * @param projectId 项目id
     * @return
     * @author Jiaqi.X
     * @createDate 2017/12/28
     */
    public JSONArray getHomeDeviceByProjectId(String userId,String projectId) throws Exception {
        //查询用户权限
        JSONArray userProjectArr = new JSONArray();
        Map<String,Object> deviceauthmap = new HashMap<>();
        deviceauthmap.put("userId",userId);
        deviceauthmap.put("currentPage",0);
        deviceauthmap.put("pageSize",100);
        deviceauthmap.put("deviceStatus",1); //启用状态的设备
        //查询用户拥有的项目列表
        Map<String,Object> projectparam = new HashMap<>();
        projectparam.put("userId",userId);
        if (StringUtils.isNotBlank(projectId)){
            projectparam.put("projectId",projectId);
        }
        List<Map<String,Object>> userProjectList = iAppOldHomeDao.getUserProject(projectparam);
        if (userProjectList != null&&userProjectList.size()>0){
            String cardNum = "000000",pubKey = "";
            String userSipAccount = "",userSipPsd = "",sipAddress="",sipPort = ""; //用户在每个项目上的SIP账号与密码
            for (Map userprojectmap:userProjectList){
                JSONObject uprjs = new JSONObject();
                uprjs.put("projectId",userprojectmap.get("projectId").toString());
                uprjs.put("projectName",userprojectmap.get("projectName").toString());
                uprjs.put("userTypeInProject",userprojectmap.get("userType").toString());
                pubKey = userprojectmap.get("pubKey").toString();
                uprjs.put("pubKey",pubKey);
                if (userprojectmap.containsKey("cardNum")&&userprojectmap.get("cardNum") != null&&StringUtils.isNotBlank(userprojectmap.get("cardNum").toString())){
                    cardNum = userprojectmap.get("cardNum").toString();
                }
                uprjs.put("cardNum",cardNum);
                if (userprojectmap.containsKey("userSipAccount")&&userprojectmap.get("userSipAccount") != null&&StringUtils.isNotBlank(userprojectmap.get("userSipAccount").toString())){
                    userSipAccount = userprojectmap.get("userSipAccount").toString();
                }
                if (userprojectmap.containsKey("userSipPsd")&&userprojectmap.get("userSipPsd") != null&&StringUtils.isNotBlank(userprojectmap.get("userSipPsd").toString())){
                    userSipPsd = userprojectmap.get("userSipPsd").toString();
                }
                if (userprojectmap.containsKey("sipAddress")&&userprojectmap.get("sipAddress") != null&&StringUtils.isNotBlank(userprojectmap.get("sipAddress").toString())){
                    sipAddress = userprojectmap.get("sipAddress").toString();
                }
                if (userprojectmap.containsKey("sipPort")&&userprojectmap.get("sipPort") != null&&StringUtils.isNotBlank(userprojectmap.get("sipPort").toString())){
                    sipPort = userprojectmap.get("sipPort").toString();
                }
                List<AppOldDeviceVO> dl = new ArrayList<>();
                deviceauthmap.put("projectId", StringHandlerUtil.getEmptyOrStr(uprjs.get("projectId")));
                //查询用户门禁设备列表
                List<Map<String,Object>> userDoorList = iAppOldHomeDao.getUserDoorList(deviceauthmap);
                AppEntranceOrCloudIntercomAuthVO appEntranceOrCloudIntercomAuthVOInDoor = StringHandlerUtil.converEntranceOrCloudIntercomAuth(PropertyEquipTypeEnum.ENTRANCE.getType(),userDoorList);
                if (appEntranceOrCloudIntercomAuthVOInDoor != null){
                    List<String> entranceIdList = appEntranceOrCloudIntercomAuthVOInDoor.getDeviceIds();
                    List<DeviceEntranceInfoPO> deviceEntranceInfoPOs = iAppOldHomeDao.getUserEntranceList(entranceIdList,userprojectmap.get("projectId").toString());
                    if (deviceEntranceInfoPOs != null&&deviceEntranceInfoPOs.size()>0){
                        for (DeviceEntranceInfoPO doorPO:deviceEntranceInfoPOs){
                            AppOldDeviceVO appOldDeviceDoorVO = new AppOldDeviceVO(doorPO.getDeviceName(), PropertyEquipTypeEnum.ENTRANCE.getType(),doorPO.getDeviceId(),
                                    DateUtil.parseString("yyyy-MM-dd HH:mm:ss",appEntranceOrCloudIntercomAuthVOInDoor.getValiTime()).getTime(),"1",doorPO.getDeviceUnique(),doorPO.getOpenThreshold(),cardNum,pubKey,"8");
                            appOldDeviceDoorVO.setProjectId(userprojectmap.get("projectId").toString());
                            if (StringUtils.isNotBlank(appOldDeviceDoorVO.getDoorAuth())){
                                appOldDeviceDoorVO.setDoorAuth(appOldDeviceDoorVO.getDoorAuth().toUpperCase());
                            }
                            dl.add(appOldDeviceDoorVO);
                        }
                    }
                }
                //查询云对讲设备列表
                List<Map<String,Object>> userCloudDoorList = iAppOldHomeDao.getUserCloudDoorList(deviceauthmap);
                AppEntranceOrCloudIntercomAuthVO appEntranceOrCloudIntercomAuthVOInCloudDoor = StringHandlerUtil.converEntranceOrCloudIntercomAuth(PropertyEquipTypeEnum.CLOUD_INTERCOM.getType(),userCloudDoorList);
                if (appEntranceOrCloudIntercomAuthVOInCloudDoor != null){
                    List<String> cloudDoorIdList = appEntranceOrCloudIntercomAuthVOInCloudDoor.getDeviceIds();
                    List<DeviceCloudIntercomInfoPO> deviceCloudIntercomInfoPOs = iAppOldHomeDao.getUserCloudIntercomDoorList(cloudDoorIdList,userprojectmap.get("projectId").toString());
                    if (deviceCloudIntercomInfoPOs != null&&deviceCloudIntercomInfoPOs.size()>0){
                        for (DeviceCloudIntercomInfoPO cloudDoorPO:deviceCloudIntercomInfoPOs){
                            AppOldDeviceVO appOldDeviceCloudDoorVO = new AppOldDeviceVO(cloudDoorPO.getDeviceName(),PropertyEquipTypeEnum.CLOUD_INTERCOM.getType(),cloudDoorPO.getDeviceId(),
                                    new Date().getTime(),"1",cloudDoorPO.getDeviceUnique(),"",cardNum,pubKey,"8");
                            appOldDeviceCloudDoorVO.setProjectId(userprojectmap.get("projectId").toString());
                            if (StringUtils.isNotBlank(cloudDoorPO.getSipAccount())){
                                appOldDeviceCloudDoorVO.setSipAccount(cloudDoorPO.getSipAccount()+"@"+sipAddress+":"+sipPort);
                                appOldDeviceCloudDoorVO.setSipPsd(cloudDoorPO.getSipPsd());
                            }
                            Map<String,Object> roomparam = new HashMap<>();
                            roomparam.put("userId",userId);
                            roomparam.put("deviceUnique", cloudDoorPO.getDeviceUnique());
                            roomparam.put("smartType",cloudDoorPO.getSmartType());
                            roomparam.put("projectId",StringHandlerUtil.getEmptyOrStr(cloudDoorPO.getProjectId()));
                            List<AppOldDeviceServeRoomVO> roomVOs = iAppOldHomeDao.getUserRoomInCloudDoorList(roomparam);
                            if (roomVOs != null&&roomVOs.size()>0){
                                for (AppOldDeviceServeRoomVO appOldDeviceServeRoomVO:roomVOs){
                                    if (StringUtils.isNotBlank(userSipAccount)){
                                        appOldDeviceServeRoomVO.setSipAccount(userSipAccount+"@"+sipAddress+":"+sipPort);
                                    }
                                    if (StringUtils.isNotEmpty(userSipPsd)){
                                        appOldDeviceServeRoomVO.setSipPsd(userSipPsd);
                                    }
                                    appOldDeviceServeRoomVO.setProjectId(StringHandlerUtil.getEmptyOrStr(cloudDoorPO.getProjectId()));
                                }
                                appOldDeviceCloudDoorVO.setRoomArr(roomVOs);
                            }
                            dl.add(appOldDeviceCloudDoorVO);
                        }
                    }
                }
                //查询电梯设备列表
                List<AppElevatorAuthDTO> userFloorList = iAppOldHomeDao.getUserFloorList(deviceauthmap);
                AppElevatorAuthVO appElevatorAuthVO = StringHandlerUtil.convertElevatorAuth(userFloorList);
                if (appElevatorAuthVO != null&&StringUtils.isNotBlank(appElevatorAuthVO.getDeviceId())){
                    List<AppElevatorInfoVO> elevatorAuthList = appElevatorAuthVO.getElevatorAuth();  //解码后的电梯权限对象集合
                    String[] floorIdArr = StringHandlerUtil.splitString(appElevatorAuthVO.getDeviceId());
                    List<String> floorIdList = Arrays.asList(floorIdArr);
                    List<DeviceElevatorInfoPO> deviceFloorInfoPOs = iAppOldHomeDao.getUserElevatorFloorList(floorIdList,userprojectmap.get("projectId").toString()); //启用状态，用户有权限的电梯集合
                    if (deviceFloorInfoPOs != null&&deviceFloorInfoPOs.size()>0){
                        for(DeviceElevatorInfoPO deviceFloorInfoPO:deviceFloorInfoPOs){
                            for (AppElevatorInfoVO appElevatorInfoVO:elevatorAuthList){
                                if (appElevatorInfoVO.getDeviceId().equals(deviceFloorInfoPO.getDeviceId())){
                                    String floorAuth = StringHandlerUtil.getAuthCodeBynNturalFloors(StringHandlerUtil.filterLastComma(appElevatorInfoVO.getLiveFloor()));
                                    AppOldDeviceVO appOldDeviceFloorVO = new AppOldDeviceVO(deviceFloorInfoPO.getDeviceName(),PropertyEquipTypeEnum.ELEVATOR.getType(),deviceFloorInfoPO.getDeviceId(),
                                            DateUtil.parseString("yyyy-MM-dd HH:mm:ss",appElevatorAuthVO.getVailTime()).getTime(),"1",deviceFloorInfoPO.getDeviceUnique(),deviceFloorInfoPO.getOpenThreshold(),cardNum,pubKey,floorAuth,
                                            deviceFloorInfoPO.getCommonFloor(),StringHandlerUtil.filterLastComma(appElevatorInfoVO.getLiveFloor()),StringHandlerUtil.filterLastComma(appElevatorInfoVO.getCommonChoiceFloor()),StringHandlerUtil.filterLastComma(appElevatorInfoVO.getLiveChoiceFloor()));
                                    if (StringUtils.isNotBlank(deviceFloorInfoPO.getCommonFloor())){
                                        List<String> commonFloorList = Arrays.asList(deviceFloorInfoPO.getCommonFloor().split(","));
                                        String commonLogicalFloor = iAppOldHomeDao.getLogicalFloor(commonFloorList, deviceFloorInfoPO.getDeviceUnique());
                                        appOldDeviceFloorVO.setCommonLogicalFloor(commonLogicalFloor);
                                    }

                                    List<String> liveFloorList = Arrays.asList(StringHandlerUtil.splitString(appElevatorInfoVO.getLiveFloor()));
                                    String liveLogicalFloor="";
                                    if(liveFloorList!=null && !liveFloorList.isEmpty()){
                                        liveLogicalFloor = iAppOldHomeDao.getLogicalFloor(liveFloorList, deviceFloorInfoPO.getDeviceUnique());
                                    }
                                    appOldDeviceFloorVO.setLiveLogicalFloor(liveLogicalFloor);
                                    appOldDeviceFloorVO.setProjectId(userprojectmap.get("projectId").toString());
                                    if (StringUtils.isNotBlank(appOldDeviceFloorVO.getFloorAuth())){
                                        appOldDeviceFloorVO.setFloorAuth(appOldDeviceFloorVO.getFloorAuth().toUpperCase());
                                    }

                                    dl.add(appOldDeviceFloorVO);
                                }
                            }
                        }
                    }
                }
                //添加用户在项目中的权限设备集合
                uprjs.put("deviceinfoArr",dl);
                userProjectArr.add(uprjs);
            }
        }
        return userProjectArr;
    }










}
